package AFTriangle;

public class AFTriangleProgram {
	
	public static void main(String args[]) {
		
		if ( args.length != 3 )
		{
			System.out.println("enter three sides");
		}
		else
		{
			classifyTriangle( Double.valueOf(args[0]), Double.valueOf(args[1]), Double.valueOf(args[2]) ); 
		}
	}

	static void classifyTriangle(double side1, double side2, double side3) {
				
		if ( isValid(side1, side2, side3) ) {
			System.out.println("Invalid Triangle");
			return;
		}
		if ( isEquilateralTriangle(side1, side2, side3) ) {
			System.out.println("Equilateral Triangle");
		}
		
		else if ( isIsoscelesTriangle(side1, side2, side3) ) {
			if ( isRightTriangle(side1, side2, side3) )
			{
				System.out.print("Right ");
			}
			System.out.println("Isosceles Triangle");
		}
		
		else if ( isScaleneTriangle(side1, side2, side3) ) {
			if ( isRightTriangle(side1, side2, side3) )
			{
				System.out.print("Right ");
			}
			System.out.println("Scalene Triangle");
		}
		else
		{
			System.out.println("Invalid Triangle");
		}
				
	}

	static boolean isValid(double side1, double side2, double side3) {
		 if( (side1 <= (side2+side3)) || (side2 <= (side1+side3)) || (side3 <= (side1+side2) ) ) {
			 return false;
		 }
		return true;
	}

	static boolean isEquilateralTriangle(double side1, double side2, double side3) {
		if ( anyInvalidSides(side1, side2, side3) ) return false;
		else if ( side1 == side2 && side1 == side3 ) {
			return true;
		}
		return false;
	}

	static boolean isIsoscelesTriangle(double side1, double side2, double side3) {
		if ( anyInvalidSides(side1, side2, side3) ) return false;
		else if ( side1 == side2 || side1 == side3 || side2 == side3 ) {
			if ( !isEquilateralTriangle(side1, side2, side3) ) {
				return true;
			}
			return false;
		}
		return false;
	}

	static boolean isScaleneTriangle(double side1, double side2, double side3) {
		if ( anyInvalidSides(side1, side2, side3) ) return false;
		else if ( side1 != side3 && side1 != side2 && side2 != side3 ) {
			return true;
		}
		return false;
	}

	static boolean anyInvalidSides(double side1, double side2, double side3) {
		if ( side1 <= 0 || side2 <= 0 || side3 <= 0 )
			return true;
		return false;
	}

	static double smallestSide(double side1, double side2, double side3) {
		if ( side1 < side2 ) {
			if ( side1 < side3 ) {
				return side1;
			}
			else return side3;
		}
		else
		{
			if ( side2 < side3 ) {
				return side2;
			}
			else return side3;
		}
	}

	static double middleSide(double side1, double side2, double side3) {
		
		if (side1 < side2 && side3 > side2 || side3 < side2 && side1 > side2)
			return side2;

		if (side3 < side1 && side2 > side1 || side2 < side1 && side3 > side1)
			return side1;

		if (side2 < side3 && side1 > side3 || side1 < side3 && side2 > side3)
			return side3;
		
		return side2;
	}

	static double biggestSide(double side1, double side2, double side3) {
		if ( side1 >= side2 ) {
			if ( side1 >= side3 ) {
				return side1;
			}
			else return side3;
		}
		else
		{
			if ( side2 >= side3 ) {
				return side2;
			}
			else return side3;
		}
		
	}

	static boolean isRightTriangle(double side1, double side2, double side3) {
		double biggest = biggestSide(side1, side2, side3);
		double middle = middleSide(side1, side2, side3);
		double smallest = smallestSide(side1, side2, side3);
		
		if ( Math.pow(smallest, 2) + Math.pow(middle, 2) == Math.pow(biggest, 2) ){
			return true;
		}
		return false;
	}
}
